package com.fick.tags;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.fick.hibernate.dao.LinkDAO;
import com.fick.hibernate.dao.NewsDAO;
import com.fick.hibernate.model.Link;

public class TextLinkTag extends TagSupport {
	
	private static Log log = LogFactory.getLog(TextLinkTag.class);
	//链接类型id
	private int classid=0;

	@Override
	public int doStartTag() throws JspException {
		try {
			StringBuffer sb = new StringBuffer();
			NewsDAO dao=new NewsDAO();
			LinkDAO linkdao=new LinkDAO();
			List<Link> list=dao.findPageBySql(Link.class,1,200,"where linkClass.classid="+classid+" order by linkOrder");
			if(list != null){
				if(list.size() != 0){
					for( int i = 0 ; i < list.size() ; i ++ ){
						Link link = (Link)list.get(i);
						if(link.getWebName().length()>6)
							link.setWebName(link.getWebName().substring(0, 6)+"...");
						String val = "<a href='"+link.getWebUrl()+"' >"+
						             link.getWebName()+"</a>";
						sb.append("<option value='"+link.getWebUrl()+"'>");
						sb.append(val);
						sb.append("</option>");
					}
				}
			}
			
			JspWriter out = pageContext.getOut();
			out.println(sb.toString());
			out.flush();
		}catch(IOException e)
		{
			log.error("标签显示错误"+e);
			e.printStackTrace();
		}
		return SKIP_BODY;
	}

	public int getClassid() {
		return classid;
	}

	public void setClassid(int classid) {
		this.classid = classid;
	}

    
}
